package com.wll.store.common.config;

import com.wll.store.common.result.Result;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 捕获的是controller中使用@RequestMapping（@GetMapping,@PostMapping）注解接口中抛出的异常
 */
@ControllerAdvice
public class BootControllerAdvice {

    //捕获具体的异常
    @ExceptionHandler(value = UnauthorizedException.class)
    @ResponseBody
    public Result<?> handle401(UnauthorizedException e) {
        e.printStackTrace();
        return new Result<>().error(HttpStatus.UNAUTHORIZED.value(), "用户没有操作权限");
    }
}
